﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TarreOA.TarreOABLL;
using TarreOA.TarreOAModels;

public partial class admin_AddLinkman : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["user"] == null)
        {
            Session["ShowMessage"] = "用户未登录，请重新登录!";
            Session["Backurl"] = "Login.aspx";
            Response.Redirect("~/Main.aspx");
        }
        else
        {
            TarreOA.TarreOAModels.User sucessUser = (User)Session["user"];
            bool userFlag = false;
            if (sucessUser.PopedomGroup.PopedomList != null)
            {
                foreach (Popedom var in sucessUser.PopedomGroup.PopedomList)
                {
                    if (var.PopedomId == 36)
                    {
                        userFlag = true;
                        break;
                    }
                }
            }
            if (!userFlag)
            {
                Session["ShowMessage"] = "用户没有该权限，请与管理员联系!";
                Session["Backurl"] = "Right.aspx";
                Response.Redirect("~/Message.aspx");
            }
        }
        if(!IsPostBack)
        {
            TarreOA.TarreOAModels.User user=(User)Session["user"];
            Label1.Text = "新建联系人（联系人总数 "+LinkmanManager.CountAllLinkman(user.UserId)+" ）";
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Linkman linkman = new Linkman();
        Client client = new Client();
        client.ClientId = Convert.ToInt32(this.hidClientId.Value);
        linkman.Client = client;
        linkman.LinkmanName = txtLinkmanName.Text.Trim();
        linkman.Sex = Convert.ToInt32(ddlSex.SelectedValue);
        linkman.Job = txtJob.Text.Trim();
        linkman.Like = txtLike.Text.Trim();
        linkman.FamilyAddress = txtFamilyAddress.Text.Trim();
        linkman.FamilyPostalcode = txtFamilyPostalcode.Text.Trim();
        linkman.JobTelephone = txtJobTelephone.Text.Trim();
        linkman.HomeTelephone = txtHomeTelephone.Text.Trim();
        linkman.HandsetNumber = txtHandsetNumber.Text.Trim();
        linkman.Email = txtEmail.Text.Trim();
        linkman.QqNumber = txtQQNumber.Text.Trim();
        linkman.Remark = txtRemark.Text;
        linkman.ShellUser=(User)Session["user"];
        if (LinkmanManager.AddLinkman(linkman))
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script language='javascript'>alert('添加成功！');</script>");
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script language='javascript'>alert('添加失败！请重试！');</script>");
        }
    }
}
